import { MovieDao } from "../dao/movie";
import { MusicDao } from "../dao/music";
import { SentenceDao } from "../dao/sentence";
import { NotFound } from "lin-mizar";

class Content {

  static async getContentList() {
    const movieList = await MovieDao.getMovieList();
    const musicList = await MusicDao.getMusicList();
    const sentenceList = await SentenceDao.getSentenceList();
    let res = [];
    res.push.apply(res, movieList);
    res.push.apply(res, musicList);
    res.push.apply(res, sentenceList);
    // console.log(res)
    // res.sort((a, b) => b.create_time.localeCompare(a.create_time));
    return res;
  }

  static async addContent(v) {
    switch (v['type']) {
      case 100:
        delete v['url']
        await MovieDao.addMovie(v);
        break;
      case 200:
        await MusicDao.addMusic(v);
        break;
      case 300:
        delete v['url']
        await SentenceDao.addSentence(v);
        break;
      default:
        throw new NotFound({ msg: '内容类型不存在' });
    }
  }


  static async editContent(id, param) {
    switch (param['type']) {
      case 100:
        delete param['url']
        await MovieDao.editMovie(id, param);
        break;
      case 200:
        await MusicDao.editMusic(id, param);
        break;
      case 300:
        delete param['url']
        await SentenceDao.editSentence(id, param);
        break;
      default:
        throw new NotFound({ msg: '内容类型不存在' });
    }
  }

  static async deleteContent(id, type) {
    switch (type) {
      case 100:
        await MovieDao.deleteMovie(id);
        break;
      case 200:
        await MusicDao.deleteMusic(id);
        break;
      case 300:
        await SentenceDao.deleteSentence(id);
        break;
      default:
        throw new NotFound({ msg: '内容类型不存在' });
    }
  }

}

export { Content as ContentService }